<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文章列表--layui后台管理模板</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../../js/layui/css/layui.css"
	media="all" />
<script src="../../js/layui/layui.js"></script>
<link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css"
	media="all" />
<link rel="stylesheet" href="../../css/news.css" media="all" />

<style type="text/css">
.layui-table-cell {
	text-align: center;
	height: auto;
	white-space: normal;
	width: auto;
}
</style>
</head>
<body class="childrenBody">
	<blockquote class="layui-elem-quote news_search">
		<form class="layui-form" method="post" onsubmit="return false;">
			<label class="layui-form-mid">类型名:</label>
			<div class="layui-input-inline">
				<input type="text" id="name" name="name" placeholder="请输入类型名"
					autocomplete="off" class="layui-input  search_input">
			</div>

			<div class="layui-input-inline" style="width: 100px;">
				<button class="layui-btn" id="search" data-type="reload">搜索</button>

			</div>
			<div class="layui-inline">
				<a class="layui-btn linksAdd_btn" style="background-color: #5FB878">添加类型</a>
			</div>
		</form>

	</blockquote>
	<div class="layui-form links_list">
		<table class="layui-table" id="deigner" lay-filter="table">

		</table>
	</div>

	<!-- <div id="page"></div> -->
	<script type="text/html" id="barDemo">
			
			<a class="layui-btn layui-btn-sm" lay-event="edit" ><i class="layui-icon layui-icon-edit"></i>编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
		</script>
	<script type="text/javascript">
		layui
				.use(
						['table','layer'],
						function() {
							var table = layui.table,
							$=layui.$,
							layer=layui.layer;
							table
									.render({
										elem : '#deigner',
										width : 1005,
										url : 'http://localhost:8080/Greenleaf/pdtClass/getAll' //数据接口
										,
										page : true,
										limit:3,
										limits:[3,4,5,10],
										cols : [ [ //表头
												{
													field : 'pdtClassId',
													title : '编号',
												},
												{
													field : 'className',
													title : '类型',
												} ,{
													title : '操作',
													align : 'center',
													fixed : 'right',
													toolbar : '#barDemo'
												}

										] ]
									,id : "DesignerReload"
									});
							$("#search")
							.click(
									function() {
										table
												.reload(
														'DesignerReload',
														{
															url : 'http://localhost:8080/Greenleaf/pdtClass/getAll',
															page : {
																curr : 1
															//重新从第 1 页开始
															},
															where : {
																name : $(
																		"#name")
																		.val()
															}
														});
									});
							table.on('tool(table)', function(obj) { 
								var data = obj.data; //获得当前行数据
								var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
								var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
								sessionStorage.setItem("productType", JSON.stringify(data));
								if(layEvent === 'del') { //删除
									layer.confirm('真的删除行么', function(index) {
										layer.close(index);
										$.post(
											"http://localhost:8080/Greenleaf/pdtClass/del",
													{pdtClassId:data.pdtClassId},function(res){
														if(res.success){
															layer.msg('删除失败,'+res.message, {
																icon : 2,
																time : 1500
															});
														}else{
															obj.del();
															layer.msg('删除成功', {
																icon : 1,
																time : 1500
															});
															location.reload();
														}
													},"json"
										)
									});
								} else if(layEvent === 'edit') { //编辑
									var id=data.pdtClassId;
									
										var index = layui.layer.open({
											title : "编辑类型",
											type : 2,
											content : "productTypeUpdate.html",
											success : function(layero, index){
												layui.layer.tips('点击此处类型列表', ' .layui-layer-close', {
													tips: 3
												});
											},
										end : function(){
											location.reload();
										} 
										})
										
										$(window).resize(function(){
											layui.layer.full(index);
										})
										layui.layer.full(index);
									
									
								}
							});
							$(".linksAdd_btn").click(function(){
								var index = layui.layer.open({
									title : "添加类型",
									type : 2,
									content : "productTypeAdd.html",
									success : function(layero, index){
										layui.layer.tips('点击此处返回类型列表', ' .layui-layer-close', {
											tips: 3
										});
									},
									end : function(){
										location.reload();
									} 
								})
								//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
								$(window).resize(function(){
									layui.layer.full(index);
								})
								layui.layer.full(index);
							})
						})
	</script>


</body>
</html>